import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/status/provider/base/base_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/change/change_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/future/future_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/multi/multi_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/proxy/proxy_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/provider/stream/straem_provider_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/widget/dark_extendable_navigation.dart';

var tabTitle = [
  "MultiProvider",
  "FutureProvider",
  "BaseProvider",
  "ChangeNotifierProvider",
  "StraemProvider",
  "Proxy+Cousumer",
];

class ProviderTestWidget extends StatefulWidget {
  const ProviderTestWidget({Key? key}) : super(key: key);

  @override
  State<ProviderTestWidget> createState() => _ProviderTestState();
}

class _ProviderTestState extends State<ProviderTestWidget> {
  final PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        DarkExtendableNavigation(
          onDestinationSelected: _onDestinationSelected,
          navigationRailDestination: buildNavigationRailDestination(),
        ),
        //占满剩余空间
        Expanded(child: buildView())
      ],
    );
  }

  void _onDestinationSelected(int value) {
    _controller.jumpToPage(value);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  Widget buildView() {
    return PageView(
        controller: _controller,
        children: tabTitle.map((e) {
          if (e == "MultiProvider") {
            return MultiProviderTestWidget();
          } else if (e == "FutureProvider") {
            return FutureProviderTestWidget();
          } else if (e == "BaseProvider") {
            return BaseProviderTestWidget();
          } else if (e == "ChangeNotifierProvider") {
            return ChangeNotifierProviderTestWidget();
          } else if (e == "StraemProvider") {
            return StraemProviderTestWidget();
          } else if (e == "Proxy+Cousumer") {
            return ProxyProviderTestWidget();
          } else {
            return Container();
          }
        }).toList());
  }

  List<NavigationRailDestination> buildNavigationRailDestination() {
    return tabTitle.map((e) {
      return NavigationRailDestination(
          icon: Icon(Icons.device_unknown), label: Text(e));
    }).toList();
  }
}
